﻿using RantopadService.Business;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RantopadService.Info
{
    public partial class MacroInfo : System.Web.UI.Page
    {
        private string macroName = "";
        private string userName = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            macroName = Request.QueryString["macroName"];
            userName = Request.QueryString["userName"];
            initData();
        }

        private void initData()
        {
            var dt = KeySettingBusiness.getMACRO(userName, macroName);
            if (dt.Rows.Count > 0)
            {
                var row = dt.Rows[0];
                NAME.Text = macroName;
                USERID.Text = userName;
                //加载按键详细设置信息
                //var table=KeySettingBusiness.getAllKeySettingsByID(row["ID"].ToString());
                var strMacro = row["CONTENT"].ToString();
                var dtMacros = XMLHelper.decodeMacroXmltoDS(strMacro);
                if (dtMacros.Tables.IndexOf(macroName)<0)
                {
                    return;
                }
                var dtMacro = dtMacros.Tables[dtMacros.Tables.IndexOf(macroName)];
                dtMacro.Columns.Add("keyname");
                foreach (DataRow item in dtMacro.Rows)
                {
                    string type = "2";
                    if (item["type"].ToString() == "mouse")
                    {
                        type = "1";
                    }
                    item["keyname"] = KeySettingBusiness.getKeyNameByID(type, item["keyid"].ToString());
                }
                GridView1.DataSource = dtMacro;
                GridView1.DataBind();
            }

        }
        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {

        }
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;
            initData();
        }
    }
}